--侦探挽尊
local zhentanwanzun = fk.CreateSkill {
    name = "mcdh_zhentanwanzun"
}

local U = require "packages/utility/utility"
local lib = require "packages/mcdh/lib"

zhentanwanzun:addEffect(fk.TargetSpecified,{
    can_trigger = function(self, event, target, player, data)
        return target == player and player:hasSkill(self) and data.card.trueName == "slash" and data.firstTarget
    end,
    on_cost = function (self, event, target, player, data)
        local room = player.room
        local aimtos = AimGroup:getAllTargets(data.tos)
        local tos = room:askForChoosePlayers(player,aimtos,1,1,"#mcdh_zhentanwanzun_chooseplayer",self.name,true)
        if #tos > 0 then
            local choices = room:askForChoices(player,{"log_spade", "log_heart", "log_club", "log_diamond"},0,4,self.name,"#mcdh_zhentanwanzun_choosesuit",false)
            self.cost_data = {room:getPlayerById(tos[1]),choices}
            return true
        end
    end,
    on_use = function (self, event, target, player, data)
        local room = player.room
        local to = self.cost_data[1] ---@type ServerPlayer
        local choices = table.map(self.cost_data[2],Util.getSuitFromString)
        local handsuit = {}
        local num = 0
        if not to:isKongcheng() then
            to:showCards(to:getCardIds(Player.Hand))
            room:delay(500)
        end
        for _, t in ipairs(to:getCardIds(Player.Hand)) do
            table.insertIfNeed(handsuit,Fk:getCardById(t).suit)
        end
        for i = 1, 4, 1 do
            if (table.contains(choices,i) and true or false) == (table.contains(handsuit,i) and true or false) then
                num = num + 1
            end
        end
        room:sendLog{
            type="#mcdh_zhentanwanzun_log",
            from = player.id,
            arg = num,
        }
        if num >= 1 then
            data.additionalDamage = data.additionalDamage or 0
            data.additionalDamage = data.additionalDamage - 1
        end
        if num >= 2 then
            if player:isAlive() then
                player:drawCards(1,self.name)
            end
            if to:isAlive() then
                to:drawCards(1,self.name)
            end
        end
        if num >= 3 then
            data.additionalDamage = data.additionalDamage or 0
            data.additionalDamage = data.additionalDamage + 2
        end
        if num >= 4 then
            data.disresponsiveList = table.map(room.alive_players, Util.IdMapper)
        end
        local use_event = room.logic:getCurrentEvent():findParent(GameEvent.UseCard, true)
        if use_event then
            room:setPlayerMark(player, "@mcdh_zhentanwanzun_num", tostring(num))
            use_event:addCleaner(function()
                room:setPlayerMark(player, "@mcdh_zhentanwanzun_num", 0)
            end)
        end
    end
})

Fk:loadTranslationTable{
    ["mcdh_zhentanwanzun"] = "挽尊",
    [":mcdh_zhentanwanzun"] = "『侦探挽尊』<br>当你使用【杀】指定目标后，你可以猜测其中一名目标角色的手牌中有无哪些花色的牌，然后其展示所有手牌。"..
            "若你猜对至少：一项，此【杀】伤害-1；两项，你与其各摸一张牌；三项，此【杀】伤害+2；四项，此【杀】不能被响应。",
    ["@mcdh_zhentanwanzun_num"] = "挽尊 猜中",
}
return zhentanwanzun